package element.synt;

import ast.AstItem;
import element.base.Synt;
import element.base.WordType;

import java.util.List;

public class FuncType extends Synt {
    public String toFormatString() {
        String format = "func<";
        Type type = (Type) getNodes().get(2);
        if (type.findFirst().isWord(WordType.FUNCTK)) {
            FuncType funcType = (FuncType) type.getNodes().getFirst();
            format += funcType.toFormatString();
        } else {
            format += type.findFirst().getContent();
        }
        if (getNodes().get(getNodes().size() - 2).isSynt(ArrayLengths.class)) {
            Type returnType = (Type) getNodes().get(getNodes().size() - 3);
            ArrayLengths arrayLengths = (ArrayLengths) getNodes().get(getNodes().size() - 2);
            List<AstItem> dims = arrayLengths.toAsts();
            int dimCount = dims.size();
            format += "_" + dimCount;
        }
        format += ">";
        return format;
    }
}
